package com.woorigil.social;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import com.woorigil.social.domain.category.Category;

public class MenuCategory {
	private Category category;
	private List<Category> subCategories = new ArrayList<Category>();
	private int dealCount;

	public void addSubCategory(Category category) {
		if (subCategories == null) {
			subCategories = new ArrayList<Category>();
		}
		subCategories.add(category);
	}
	

	public List<Integer> getSubCategoryIds() {
		List<Integer> ids = new ArrayList<Integer>();
		for (Category each : subCategories) {
			ids.add(each.getId());
		}
		return ids;
	}	
	
	public Category getCategory() {
		return category;
	}
	public void setCategory(Category category) {
		this.category = category;
	}
	public int getDealCount() {
		return dealCount;
	}
	public void setDealCount(int dealCount) {
		this.dealCount = dealCount;
	}
	public List<Category> getSubCategories() {
//		Collections.sort(subCategories, new OrderComparator());
		return subCategories;
	}
	public void setSubCategories(List<Category> subCategories) {
		this.subCategories = subCategories;
	}
	
	public class OrderComparator implements Comparator<Category> {
		@Override
		public int compare(Category p1, Category p2) {
			if (p1.getOrderNo() < p2.getOrderNo()) {
				return 1;
			} else if (p1.getOrderNo() > p2.getOrderNo()) {
				return -1;
			} else {
				return 0;
			}
		}		
	}
}
